package PAPFastSwap;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.RDFS;

public class ReadeRdf_Base {

	public static void main(String[] args) {
		File f = new File("src/ontologies/reference_huma_mouse.rdf");
//		File f = new File("src/ontologies/ReferenceAlignment.rdf");
		FileReader fr;
		try {
			fr = new FileReader(f);
			Model model = ModelFactory.createDefaultModel();
			model.read(fr, RDFS.getURI());

			StmtIterator iter = model.listStatements();
			ArrayList<String> alignRDF = new ArrayList<String>();
			
			boolean flag = false;
			String align = "";
			while (iter.hasNext()) {
				Statement stmt = iter.next();
				// System.out.println(stmt);
				// Now use <stmt>
				if (stmt.getObject().toString().equals("=")){
					flag = true;
				} 
				if(stmt.getPredicate().getLocalName().equals("alignmententity2") && flag){
					align += stmt.getObject().asResource().getLocalName();
				}
				
				if(stmt.getPredicate().getLocalName().equals("alignmententity1") && flag){
					align += (" - " + stmt.getObject().asResource().getLocalName());
					alignRDF.add(align);
					align = "";
					flag = false;
				}
			}
			for (String string : alignRDF) {
				System.out.println(string);
			}

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

// public static void main(String[] args) {
// File f = new File("src/ontologies/ReferenceAlignment.rdf");
// FileReader fr;
// try {
// fr = new FileReader(f);
// Model model = ModelFactory.createDefaultModel();
// model.read(fr, RDFS.getURI());
//
// ResIterator resourceIter = model.listSubjectsWithProperty(
// model.createProperty("http://knowledgeweb.semanticweb.org/heterogeneity/"),
// "alignmentrelation");
// while (resourceIter.hasNext()) {
// Resource r = resourceIter.next();
// System.out.println("Resource " + r.toString()
// + " is about travel to Africa");
// }
//
// // StmtIterator iter = model.listStatements();
// // while (iter.hasNext()) {
// // Statement stmt = iter.next();
// // //System.out.println(stmt);
// // // Now use <stmt>
// // Resource subject = stmt.getSubject();
// // System.out.println("Subject = " + subject.getURI());
// // Property predicate = stmt.getPredicate();
// // System.out.println("Predicate = " +predicate.getURI());
// // RDFNode obj = stmt.getObject();
// // System.out.println("Object = " + obj.toString());
// // System.out.println("________________________________________________");
// // }
//
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// }

